﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebApl.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UploadController : ControllerBase
    {

       public UploadController(IWebHostEnvironment web)
        {
            Web = web;
        }

        public IWebHostEnvironment Web { get; }


        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="file"></param>
        /// <returns>返回受影响行数</returns>
        /// 
        [HttpPost]
         public IActionResult up(IFormFile file)
        {

            try//异常处理
            {
                 var  mpp=Guid.NewGuid().ToString();
                 var path=Web.WebRootPath +@"\pic\"+ mpp+file.FileName;

                using (FileStream fs = System.IO.File.Create(path))
                {

                    file.CopyTo(fs);
                     fs.Close();

                }
                return Ok(@"/pic/"+mpp+file.FileName);
            }

            catch (Exception)
            {

                throw;
            }

        }
    }
}
